home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / Copy_of_LockPubScreenListPatch < prev    next >
Text File  |  1998-09-06  |  3KB  |  131 lines

  1. //#define DEBUG
  2.  
  3. #include "MP.h"
  4. #include <debug.h>
  5. #include <exec/lists.h>
  6.  
  7. extern struct MPSem *MPSem;
  8.  
  9. // LockPubScreenList
  10. extern struct List * __asm (*OldLockPubScreenList)(register __a6 struct Library *);
  11. extern void __asm (*OldUnlockPubScreenList)(register __a6 struct Library *);
  12.   
  13. struct List PubScreenList;
  14. LONG PubListNest=0; // If Zero then Init 
  15.  
  16. struct PubScreenNode BuggyPSN;
  17.  
  18. struct List * __saveds __asm NewLockPubScreenList(register __a6 struct IntuitionBase *IBase)
  19. {
  20.   struct PubScreenNode *psn,*npsn;
  21.   struct DefaultNode *dnode;
  22.   struct List *list;
  23.   char tnamebuffer[52];
  24.   char *tname;
  25.   
  26.   tname=SetupTaskName(tnamebuffer," in NewLockPubScreenList()",50);
  27.   
  28. DEBUG_CODE(
  29.   DKP("LockPubScreenList()\n");
  30.   )  
  31.  
  32.   ObtainSemaphoreShared(&MPSem->ListSem); 
  33.   ObtainSemaphore(&MPSem->NodeSem);
  34.   
  35.   list=OldLockPubScreenList((struct Library *)IBase);
  36.  
  37.   /* Clone Old PS list */
  38.   
  39.   if(PubListNest==0)
  40.   {
  41.     // The OS nests calls to LockPubScreenList()/UnlockPubScreenList() only create the list when PubListNest==0
  42.     NewList(&PubScreenList);
  43.  
  44.     psn=(struct PubScreenNode *)list->lh_Head;
  45.     while(psn->psn_Node.ln_Succ)
  46.     {
  47.       if(npsn=AllocVec(sizeof(*npsn),MEMF_PUBLIC))
  48.       {
  49.         *npsn=*psn;
  50.         AddTail(&PubScreenList,(struct Node *)npsn);
  51.       }
  52.       
  53.       psn=(struct PubScreenNode *)psn->psn_Node.ln_Succ;
  54.     }
  55.     
  56.     /* Make PSNodes for MP's pubscreens */
  57.     
  58.     dnode=(struct DefaultNode *)MPSem->PromotionList[PL_PUBLICSCREENS].lh_Head;
  59.   
  60.     while(dnode->Def_Node.ln_Succ)
  61.     {
  62.       if(!FindName(&PubScreenList,dnode->Def_Node.ln_Name))
  63.       { /* Avoid Duplicates */
  64.         if(npsn=AllocVec(sizeof(*npsn),MEMF_PUBLIC|MEMF_CLEAR))
  65.         {
  66.           npsn->psn_Node.ln_Name=dnode->Def_Node.ln_Name; // Safe to reference name since lists are protected till UnlockPubScreenList() 
  67.           AddTail(&PubScreenList,(struct Node *)npsn);
  68.         }
  69.       }
  70.       dnode=(struct DefaultNode *)dnode->Def_Node.ln_Succ;
  71.     }
  72.   }
  73.   else
  74.   {
  75.     // nested
  76.   }
  77.  
  78.  
  79. /*
  80.   {
  81.     LONG *l,q;
  82.     
  83.     l=0;
  84.     
  85.     *l=0;
  86.   }*/
  87.   
  88.   PubListNest++; // Some dumb apps call LockPubScreen() inside LockPubScreenList()/UnlockPubScreenList()
  89.   
  90.   SetTaskName(tname);
  91.   
  92.   return(&PubScreenList);
  93. }
  94.  
  95. void __saveds __asm NewUnlockPubScreenList(register __a6 struct IntuitionBase *IBase)
  96. {
  97.   struct PubScreenNode *psn;
  98.   char tnamebuffer[52];
  99.   char *tname;
  100.   
  101.   tname=SetupTaskName(tnamebuffer," in NewUnlockPubScreenList()",50);
  102.  
  103.  
  104.   BuggyPSN.psn_Node.ln_Name="Bad LockPubScreenList() Access";
  105.    //                        1234567890123456789012345678901234567890
  106.    //                                 0         0         0         0
  107.   PubListNest--;
  108.   
  109.   if(PubListNest==0)
  110.   {
  111.     while(psn=(struct PubScreenNode *)RemHead(&PubScreenList))
  112.     {
  113.       FreeVec(psn);
  114.     }
  115.     // Add bug alert 
  116.     AddHead(&PubScreenList,(struct Node *)(&BuggyPSN));
  117.   }
  118.   
  119.   OldUnlockPubScreenList((struct Library *)IBase);
  120.   
  121.   
  122. DEBUG_CODE(
  123.   DKP("UnlockPubScreenList()\n");
  124.   )  
  125.  
  126.   SetTaskName(tname);
  127.   
  128.   ReleaseSemaphore(&MPSem->NodeSem);      
  129.   ReleaseSemaphore(&MPSem->ListSem);
  130. }
  131.